import requests
import time
import ast
def requestFromServer(host="localhost"):
    response = requests.get(url='http://%s:8888/command'%host)
    response.encoding = 'utf-8'
    with open('requestlog.log', 'a', encoding='utf-8') as f:
        s= "time: "+repr(time.time())+' resp:'+response.text+'\n'
        # print(s)
        if(s.find("idle")!=-1):
            pass
        else:
            print(s)
            f.write(s)
    if(response.text.find('idle')!=-1):
        return None
    else:
        return ast.literal_eval(response.text)

    # return response.text

if __name__=="__main__":
    while(1):
        requestFromServer(host='117.73.9.242')
        time.sleep(0.1)